<?php

class TEParser extends Parser{
	
	public function __construct($objectParent){
		$this->objectParent = & $objectParent; 
		$this->addPattern(
			(new BlockPattern())
			    ->setAction(array($this,'createBlock'))
		);
		
	}
	
	public function createBlock($matches){
		$properties=array();
		print_r($matches);echo "<hr>";
		$objectClass = !empty($matches[1])?trim($matches[1]):(!empty($matches[6])?trim($matches[6]):"");
		$id          = !empty($matches[2])?trim($matches[2]):(!empty($matches[7])?trim($matches[7]):"");
		$argument    = !empty($matches[3])?$matches[3]:""; 
		$text        = !empty($matches[4])?$matches[4]:"";
		$tag         = !empty($matches[9])?trim($matches[9]):"";
		
		$propertyPattern = new PropertyPattern();
		
		$matches = $propertyPattern->matchAll($argument);
		if($matches)
			foreach($matches as $match){
				$property = $match[1];
				$value    = $match[3];
				$properties[$property] = $this->parse($value);
		}
		//Construye un block
		if($objectClass && $id){
			$self = & $this;
			$builder = new BlockBuilder();
			$builder->createBlock($objectClass,$id,$self,$properties,$text);
			$this->$id = $builder->getBlock();
			if(method_exists($this->$id,'show')){
				return $this->$id->show();
			}else{
				return $this->$id->parse($this->$id->block);
			}
		}
		//llamar a un metodo o propiedad
		if(!$objectClass && $id){
			if(method_exists($this,$id)){
				return $this->$id($properties,$text);
			}else{
				if(isset($this->$id))
					return $this->$id;
			}
		}
		//llamar a un tag
		if($tag){
			if(isset($this->$tag)){return $this->$tag;}
		}
	}//end createBlock
	
	
}//end class

?>